 # 导包
import unittest, requests
from api.log import LogSignleton
import pymysql
import xlrd,re
from api.getpath import GetTestDataPath
from scripts.TestRequest import TestPostRequestCookie
testdata = xlrd.open_workbook(GetTestDataPath())


def regist_success():
    # 注册的接口的URL
    url_verify = "http://localhost/index.php?m=Home&c=User&a=verify&type=user_reg"
    url_regist = "http://localhost/index.php/Home/User/reg.html"
    mobile = "13800000127"
    cookies = requests.get(url_verify).cookies

    datas = "auth_code=TPSHOP&scene=1&username="+mobile+"&verify_code=8888&password=519475228fe35ad067744465c42a19b2&password2=519475228fe35ad067744465c42a19b2"
    print(datas)
    headers = {"Content-Type": "application/x-www-form-urlencoded"}
    try:
        testcaseid = "1-1"
        testname = "拉钩注册" + testcaseid
        testhope = "注册成功"
        # print(testhope)
        fanhuitesthpe = "注册成功"
        # print(fanhuitesthpe)

        r = TestPostRequestCookie(url_regist, datas, headers, testcaseid, testname, testhope,
                                  fanhuitesthpe,cookies,"msg")

        # print(r)
    except Exception as e:
        print(e)

    print(" 开始删除注册的手机号码：",mobile)

    conn = pymysql.connect(host="localhost", port=3306, user="root", password="root", database="tpshop2.0",
                           charset="utf8")
    # 获取游标
    cursor = conn.cursor()
    # 执行SQL语句
    cursor.execute('DELETE from tp_users where mobile='+mobile+';')
    # `uname` = '"+member[1]+"'
    # 提交事务
    conn.commit()
    # 执行完成之后，在navicat当中，查看结果13800000125

    # 关闭游标
    cursor.close()
    # 关闭连接
    conn.close()


regist_success()
